﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Com.CMS263.Util;
using Com.CMS263.PO;
using Com.CMS263.BLL;
using System.IO;

namespace Com.CMS263.Web.manage.GuestManage
{
    public partial class stu_edit : System.Web.UI.Page
    {
        StudentInfoBLL sibll = new StudentInfoBLL();
        public int id = 0;
        public int page = 0;
        public StudentInfo sinfo = new StudentInfo();
        protected void Page_Load(object sender, EventArgs e)
        {
            page = Convert.ToInt32(Request["page"]);
            id = Convert.ToInt32(Request["id"]);
            if (id <= 0)
            {
                StringUtil.Alert("抱歉,没有数据", "stu_list.aspx");
            }
            sinfo = (StudentInfo)sibll.FindModelById("StudentInfo", id);
        }
        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnSave_Click(object sender, EventArgs e)
        {
            int id = Convert.ToInt32(Request["id"]);
            StudentInfo si = (StudentInfo)sibll.FindModelById("StudentInfo", id);
           
            string realname = StringUtil.checkStr(Request["txtRealName"]);
            if (string.IsNullOrEmpty(realname))
            {
                StringUtil.Alert("请输入姓名", "-1");
            }
            string classname = StringUtil.checkStr(Request["txtClassName"]);
            if (string.IsNullOrEmpty(classname))
            {
                StringUtil.Alert("请输入班级", "-1");
            }
            string stunum = StringUtil.checkStr(Request["txtStuNum"]);
            if (string.IsNullOrEmpty(stunum))
            {
                StringUtil.Alert("请输入学号", "-1");
            }
            
            string userpass = StringUtil.checkStr(Request["txtUserPass"]);
            if (string.IsNullOrEmpty(userpass))
            {
                StringUtil.Alert("请输入密码", "-1");
            }
            
            si.Age = StringUtil.checkStr(Request["txtAge"]);
            si.ClassName = classname;
            
            si.ParentMobilePhone = StringUtil.checkStr(Request["txtPhone"]);
            si.RealName = realname;
            si.StuNum = stunum;
            
            si.UserPass = userpass;
            si.TeacherEmail = StringUtil.checkStr(Request["txtTeacherEmail"]);
            si.TeacherMessage = Request["txtTeacherMessage"];
            string strDay = DateTime.Now.ToString("yyyy-MM-dd");
            string savePath = Server.MapPath("/ArtUpFile/" + strDay);
            if (!Directory.Exists(savePath))
            {
                Directory.CreateDirectory(savePath);
            }
            HttpPostedFile hpf = Request.Files["txtHeadImage"];
            string val = "";
            if (hpf.ContentLength < 5)
            {
                val = "";
            }
            else
            {

                val = strDay + "/" + UpLoadFileUtil.UpLoadFile(Request.Files["txtHeadImage"], savePath, "1");
            }
            if (val.Length > 10)
            {
                si.HeadImage = val;
            }
            sibll.entity = si;
            if (sibll.UpDate())
            {
                StringUtil.Alert("修改成功", "stu_list.aspx?page="+page);
            }


        }
        
    }
}
